﻿using System;
using Assets.Scripts.Tool;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI.Panel
{
    /// <summary>
    /// 提示的类型
    /// </summary>
    public enum TipType
    {
        EnterExam,//进入考试
        ExitAppliction,//退出程序
        ExitExam,//退出考试
        SubmitPaper,//提交试卷
        AutoDestroy,//自动销毁的提示信息，没有Button
    }
    public class TipPanel : UIBase<TipPanel> 
    {
        public Text TipText;
        public Button SureButton;
        public Button CancleButton;

        private TipType tipType { get; set; }

        private Action onSureButtonClick { get; set; }
            
        protected override UIType UIType
        {
            get { return UIType.Panel; }
        }

        protected override void InitOnAwake()
        {
            AutoFindComponent(transform, true);
            SureButton.onClick.AddListener(OnSureButtonClick);
            CancleButton.onClick.AddListener(Exit);
        }

        /// <summary>
        /// 初始化提示信息
        /// </summary>
        /// <param name="tipText"></param>
        /// <param name="onSureButtonClick"></param>
        public void Init(string tipText,Action onSureButtonClick)
        {
            tipType = tipType;
            TipText.text = tipText;
            this.onSureButtonClick = onSureButtonClick;
        }

        /// <summary>
        /// 只显示提示信息
        /// </summary>
        /// <param name="tipText"></param>
        public void Init(string tipText)
        {
            transform.Find("Background").gameObject.SetActive(false);
            SureButton.gameObject.SetActive(false);
            CancleButton.gameObject.SetActive(false);
            TipText.text = tipText;
            TipText.color=new Color(0.7f,0,0);
            gameObject.AddComponent<DestroyTool>();
        }

        /// <summary>
        /// 确定退出按钮的点击事件
        /// </summary>
        private void OnSureButtonClick()
        {
            if (onSureButtonClick != null)
            {
                onSureButtonClick();
            }
            Exit();
        }
    }
}
